"use strict";
cc._RF.push(module, '3bfc4IdcSFAfJaata5Tazlu', 'levelAvoidPlayer');
// scripts/modes/normalMode/levelAvoid/base/levelAvoidPlayer.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../../../../engines/gameEngine");
var levelAvoidBase_1 = require("../levelAvoidBase");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var levelAvoidPlayer = /** @class */ (function (_super) {
    __extends(levelAvoidPlayer, _super);
    function levelAvoidPlayer() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.levelbase = null;
        _this.lifeNum = 3;
        _this.lifeGroup = null;
        _this.isWudi = false;
        _this.nowLifeNum = null;
        _this.isDeathIng = false;
        return _this;
    }
    levelAvoidPlayer.prototype.onLoad = function () {
        this.nowLifeNum = this.lifeNum;
        this.setLifeGroup();
    };
    levelAvoidPlayer.prototype.setLifeGroup = function (ani) {
        if (ani === void 0) { ani = false; }
        if (!this.lifeGroup)
            return;
        for (var i = 0; i < this.lifeGroup.childrenCount; i++) {
            this.lifeGroup.children[i].active = i <= this.nowLifeNum;
        }
        if (ani) {
            var node_1 = this.lifeGroup.children[this.nowLifeNum];
            if (node_1) {
                cc.tween(node_1)
                    .to(0.2, { opacity: 0 })
                    .to(0.2, { opacity: 255 })
                    .to(0.2, { opacity: 0 })
                    .to(0.2, { opacity: 255 })
                    .to(0.2, { opacity: 0 })
                    .call(function () {
                    node_1.opacity = 255;
                    node_1.active = false;
                })
                    .start();
            }
        }
        else {
            this.lifeGroup.children[this.nowLifeNum] && (this.lifeGroup.children[this.nowLifeNum].active = false);
        }
    };
    levelAvoidPlayer.prototype.onCollisionEnter = function (other, self) {
        // console.log('on collision enter');
        if (!this.levelbase.startGame)
            return;
        if (this.levelbase.isPause && this.levelbase.playStopMove)
            return;
        if (this.isWudi)
            return;
        switch (other.tag) {
            case 444:
                this.death();
                break;
        }
    };
    levelAvoidPlayer.prototype.death = function () {
        var _this = this;
        if (this.isDeathIng)
            return;
        this.isDeathIng = true;
        this.nowLifeNum--;
        this.setLifeGroup(true);
        gameEngine_1.default.getManagers().soundMgr.playSound("fontChase/death").then();
        gameEngine_1.default.getManagers().soundMgr.playVibrate();
        if (this.nowLifeNum == 0) {
            this.levelbase.gamePause(true);
            var nowScale = this.node.scale;
            cc.tween(this.node)
                .to(0.2, { scale: nowScale - 0.2, opacity: 255 })
                .to(0.2, { scale: nowScale, opacity: 100 })
                .to(0.2, { scale: nowScale - 0.2, opacity: 255 })
                .to(0.2, { scale: nowScale, opacity: 100 })
                .to(0.2, { scale: nowScale, opacity: 255 })
                .call(function () {
                _this.levelbase.Lose();
            })
                .start();
        }
        else {
            var endscale = 0;
            switch (this.nowLifeNum) {
                case 2:
                    endscale = 0.75;
                    break;
                case 1:
                    endscale = 0.5;
                    break;
            }
            var nowScale = this.node.scale;
            cc.tween(this.node)
                .to(0.2, { scale: endscale, opacity: 255 })
                .to(0.2, { scale: nowScale, opacity: 100 })
                .to(0.2, { scale: endscale, opacity: 255 })
                .to(0.2, { scale: nowScale, opacity: 100 })
                .to(0.2, { scale: endscale, opacity: 255 })
                .call(function () {
                _this.levelbase.playStopMove = true;
            })
                .delay(1)
                .call(function () {
                _this.isDeathIng = false;
                // this.levelbase.gamePause(false)
            })
                .start();
        }
    };
    __decorate([
        property({ type: levelAvoidBase_1.default, displayName: "主节点" })
    ], levelAvoidPlayer.prototype, "levelbase", void 0);
    __decorate([
        property()
    ], levelAvoidPlayer.prototype, "lifeNum", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "剩余生命值" })
    ], levelAvoidPlayer.prototype, "lifeGroup", void 0);
    __decorate([
        property({ displayName: "是否无敌" })
    ], levelAvoidPlayer.prototype, "isWudi", void 0);
    levelAvoidPlayer = __decorate([
        ccclass
    ], levelAvoidPlayer);
    return levelAvoidPlayer;
}(cc.Component));
exports.default = levelAvoidPlayer;

cc._RF.pop();